﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.models.world.vos.actors.machines {
    import flash.events.*;
    import net.wooga.pets.loading.vos.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;

    public class ReceptionMachineVO extends AbstractMachineVO {

        private var _isOpen:Boolean;// = false
        private var _waitingForDiseaseBubbleToClose:Boolean;
        protected var _isPatientTelling:Boolean;
        private var _diagnosisTime:int;
        private var _pendingAcceptCall:Boolean;// = false

        public function ReceptionMachineVO(_arg1:Object, _arg2:IEventDispatcher){
            super(_arg1, _arg2);
        }
        override public function handlePatient(_arg1:ITreatable):void{
            if (_patient){
                _arg1.moveToNextTarget(GameConstants.TYPE_ENTRANCE_AREA);
                dispatch(new InfoEvent(EventConstants.REPORT_PROBLEM, null, ((("There is already Patient " + _patient.id) + " in the reception and no place for ") + _arg1.id)));
            } else {
                if (_arg1.state == WorldConstants.ILL){
                    _patient = _arg1;
                    _patient.clickHandler = this.onPatientClicked;
                    dispatch(new InfoEvent(EventConstants.TURN_LEFT, _arg1.id));
                    _patient.showSpeechBubble(SpeechBubbleConstants.TYPE_ICON_BUBBLE, {icon:SpeechBubbleConstants.ICON_EXCLAMATIONMARK});
                    dispatch(new InfoEvent(EventConstants.ON_ARRIVAL_AT_RECEPTION, _patient.id));
                    dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_PET_ARRIVES_IN_RECEPTION));
                } else {
                    if ((((_arg1.state == WorldConstants.PATIENT)) && ((_arg1.targetType == null)))){
                        dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _arg1.id, (("Patient " + _arg1.id) + " is already accepted")));
                        dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                    } else {
                        if (_arg1.state == WorldConstants.CURED){
                            dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _arg1.id, (("Patient " + _arg1.id) + " is already cured")));
                            dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                        } else {
                            if (_arg1.state == WorldConstants.BABY){
                                dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _arg1.id));
                                dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                            };
                        };
                    };
                };
            };
            dispatch(new Event(EventConstants.UPDATE_MORE_PETS_ARROW));
        }
        public function get waitingForDiseaseBubbleToClose():Boolean{
            return (this._waitingForDiseaseBubbleToClose);
        }
        protected function onPatientClicked():void{
            var _local1:Object;
            var _local2:InfoEvent;
            if (!this._isPatientTelling){
                this._isPatientTelling = true;
                _local1 = {method:this.onArrivalOfAvatar, params:[]};
                _local2 = new InfoEvent(EventConstants.CALL_METHOD, null, _local1);
                dispatch(new InfoEvent(EventConstants.ADD_ACTION_TO_AVATAR, roomId, _local2));
            } else {
                this.acceptPatient();
            };
        }
        protected function onArrivalOfAvatar():void{
            var _local1:InfoEvent;
            if (!_patient){
                return;
            };
            if (_patient.diseaseName == WorldConstants.DISEASE_OLD){
                this.acceptPatient();
                dispatch(new Event(EventConstants.SHOW_TREE));
                dispatch(new Event(EventConstants.SHOW_INVENTORY_GEMS));
                dispatch(new Event(EventConstants.HANDLE_NEXT_AVATAR_ACTION));
            } else {
                if (_patient.isNewDisease){
                    this._waitingForDiseaseBubbleToClose = true;
                    _local1 = new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.NEW_DISEASE_POPUP, _patient);
                    dispatch(_local1);
                } else {
                    this.startReceptionTimer();
                };
            };
        }
        public function storyOfSicknessAnimationComplete(_arg1:String):void{
            if (((!(_patient)) || (!((patient.id == _arg1))))){
                return;
            };
            this.acceptPatient();
        }
        public function startReceptionTimer():void{
            if (!_patient){
                return;
            };
            dispatch(new InfoEvent(EventConstants.SHOW_RECEPTION_BUBBLE, _patient.id, _patient));
            this._waitingForDiseaseBubbleToClose = false;
            dispatch(new InfoEvent(EventConstants.SET_ANIMATION_STATE, _patient.id, GameConstants.ANIMATION_STATE_CHAT));
            dispatch(new Event(EventConstants.HANDLE_NEXT_AVATAR_ACTION));
        }
        override protected function handleTick(_arg1:int):void{
            this.acceptPatient();
        }
        protected function acceptPatient():void{
            if (this._pendingAcceptCall){
                return;
            };
            this._pendingAcceptCall = true;
            _patient.clickHandler = null;
            this._isPatientTelling = false;
            var _local1:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST, this.onAccept);
            _local1.addRequest("accept_patient", {id:_patient.id});
            dispatch(_local1);
        }
        override public function get isFree():Boolean{
            return ((_patient == null));
        }
        public function set isOpen(_arg1:Boolean):void{
            this._isOpen = _arg1;
        }
        private function onAccept(_arg1:ResultVO):void{
            this._pendingAcceptCall = false;
            if (_arg1.success){
                dispatch(new InfoEvent(EventConstants.ENABLE_VIEW, _patient.id));
                _patient.state = WorldConstants.PATIENT;
                _patient.moveToNextTreatment();
                _patient = null;
                dispatch(new InfoEvent(EventConstants.HANDLE_NEXT_IN_QUEUE, type));
                dispatch(new InfoEvent(EventConstants.ON_PATIENT_ACCEPTED, null));
            } else {
                dispatch(new InfoEvent(EventConstants.ENFORCE_NEXT_PATIENT_ACTION, _patient.id, ((("Status for " + _patient.id) + " could not be set to ill: ") + _arg1.status)));
                dispatch(new InfoEvent(EventConstants.ON_PATIENT_REJECTED, null));
            };
            dispatch(new Event(EventConstants.UPDATE_MORE_PETS_ARROW));
        }
        override public function getAction(_arg1:Object):InfoEvent{
            var _local2:InfoEvent;
            if (!this._isOpen){
                dispatch(new Event(EventConstants.DISABLE_FRIENDS_MENU));
                this._isOpen = true;
                _local2 = new InfoEvent(EventConstants.SHOW_PATIENT_POOL_COMMAND, id);
            };
            return (_local2);
        }
        public function get diagnosisTime():int{
            return (this._diagnosisTime);
        }
        public function set diagnosisTime(_arg1:int):void{
            this._diagnosisTime = _arg1;
        }

    }
}//package net.wooga.pets.models.world.vos.actors.machines 
